package com.robocup.cameratest;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.view.View;
import android.widget.SeekBar;
import android.graphics.Color;



@SuppressWarnings("unused")
public class Cameratest1Activity extends Activity {
	
	SeekBar ColorBar;
	View targetView;
	
	private static final String TAG            = "Sample::Activity";
	
	private MenuItem            mItemgreen;
    private MenuItem            mItemred;
    
    public int bgcolor;
	
	
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	Log.i(TAG, "onCreate");
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        
        targetView = (View)findViewById(R.id.mainlayout);
        
       ColorBar = (SeekBar)findViewById(R.id.ColorBar);
       
       ColorBar.setOnSeekBarChangeListener(seekChangeListener);
        
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        Log.i(TAG, "onCreateOptionsMenu");
        mItemgreen = menu.add("Green");
        mItemred = menu.add("Red");
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        Log.i(TAG, "Menu Item selected " + item);
        if (item == mItemgreen) {
            bgcolor=android.graphics.Color.GREEN;
            Log.i(TAG, "Set to green: " + bgcolor);
            ColorBar.setProgress(bgcolor);
            updateBackgroundColor();
            Log.i(TAG, "Color: " + bgcolor);
        }
        else if (item == mItemred) {
        	bgcolor=android.graphics.Color.RED;
        	Log.i(TAG, "Set to red: " + bgcolor);
        	ColorBar.setProgress(bgcolor);
        	updateBackgroundColor();
        	Log.i(TAG, "Color: " + bgcolor);
        }
        return true;
    }
     
    private SeekBar.OnSeekBarChangeListener seekChangeListener = new SeekBar.OnSeekBarChangeListener(){
    
	     public void onProgressChanged(SeekBar ColorBar, int progress, boolean fromUser) {
	    	 bgcolor=progress;
	    	 Log.i(TAG, "ColorBar value changed: " + progress);
	    	 updateBackgroundColor();
	     }
	    
	     public void onStartTrackingTouch(SeekBar ColorBar) {
	    	 Log.i(TAG, "ColorBar Pressed");
	       
	     }
	    
	     public void onStopTrackingTouch(SeekBar ColorBar) {
	    	 Log.i(TAG, "ColorBar Released");  
	     }
     };
    
    private void updateBackgroundColor(){
    	  	int color = bgcolor;
    	  	targetView.setBackgroundColor(color+0xFF000000);
    	  	Log.i(TAG, "Changed Color to: " + bgcolor);
    	 }
    
}
    



